package edu.uc.dao;

import java.util.HashMap;

import edu.uc.dto.User;

/**
 * UserProviderStub is a hard-coded implementation of IUserDAO.
 *
 * @author Bander
 *
 */
public class UserProviderStub implements IUserDAO {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void save(User user) throws Exception {
		if (!(user.getUsername() == null || user.getUsername().equals("")) && !(user.getPassword() == null || user.getPassword().equals("")))
		{
			//run code
		}else
		{
			//throw an exception
			throw new Exception("Username and/or password fields of User object are blank.");
		}

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public User fetch(String username) throws Exception {
		//create a user
		User user = new User();
		
		if(username.equals("Caz"))
		{
			//create user object with userName = "Caz", firstName = "Caz", lastName = "Dolowicz"
			user.setFirstName("Caz");
			user.setLastName("Dolowicz");
			user.setUsername("Caz");
			user.setPassword("Caz_Password");
			user.setPhoneNumber("123456789");
			user.setPrefix("Mr.");
		}else
		{
			//throw an exception
			throw new Exception("Specified username not found.");
		}
		
		//return the user object
		return user;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public HashMap<String, User> fetchAll() {
		//create hashmap of users
		HashMap<String, User> userMap = new HashMap<String, User>();
		
		//create user object with userName = "Caz", firstName = "Caz", lastName = "Dolowicz"
		User user = new User();
		user.setFirstName("Caz");
		user.setLastName("Dolowicz");
		user.setUsername("Caz");
		user.setPassword("Cha5e5Cars");
		user.setPhoneNumber("123456789");
		user.setPrefix("Mr.");
		
		//add user to hashmap
		userMap.put(user.getUsername(), user);
		
		//return hashmap of users
		return userMap;
	}

}
